package com.zhike.mobileimsdk.server.utils;

import java.net.Inet4Address;

import com.zhike.mobileimsdk.server.ServerLauncher;
import com.zhike.mobileimsdk.server.network.Gateway;
import com.zhike.mobileimsdk.server.network.GatewayTCP;
import com.zhike.mobileimsdk.server.network.GatewayWebsocket;

public class NodeUtil {
    public static String node(String host, Integer port) {
        String node = host + ":" + port;
        return node;
    }

    public static String thisNode() {
        try {
            final String ip = Inet4Address.getLocalHost().getHostAddress();
            if (Gateway.isSupportTCP(ServerLauncher.supportedGateways)) {
                return node(ip, GatewayTCP.PORT);
            }
            if (Gateway.isSupportWebSocket(ServerLauncher.supportedGateways)) {
                return node(ip, GatewayWebsocket.PORT);
            }
        } catch (Exception e) {
            e.printStackTrace();
        }

        return "";
    }
}
